#!/bin/bash
#
# Copyright 2007 Google Inc. All Rights Reserved.
# Author: alyssad@google.com (Alyssa Daw)
#
# Run the sites liberation tool with the correct parameters.
E_BAD_MOVE=1
if [[ $# -lt 4 ]]; then
  echo "Usage: $0 [local_site_path] [liberation_jar_file] dev-[username]
    [username@your-organization.org]"
  exit "${E_BAD_MOVE}"
fi
DIR=${1}
JAR=${2}
WEBSP=${3}
USR=${4}
CLASS="com.google.sites.liberation.imprt.Main"
DOMAIN="educationcommons.rw"
if [[ ! -f "${JAR}" ]]; then
  echo "${JAR} does not exist; please supply the path to the liberation jar file."
  exit "{$E_BAD_MOVE}"
fi
if ! read -s -p "Password: " pass; then
  echo "Unable to read password."
  exit "${E_BAD_MOVE}"
fi
echo ""
if ! java -classpath "${JAR}" "${CLASS}" -d "${DOMAIN}" -w "${WEBSP}" -u "${USR}" \
    -p "${pass}" -f "${DIR}"; then
  echo "There were errors executing the jar."
  exit "${E_BAD_MOVE}"
fi
